package com.qmmessage.sdk.client;

import com.qmmessage.sdk.common.exception.QmMessageSdkException;
import com.qmmessage.sdk.common.profile.ClientProfile;
import com.qmmessage.sdk.models.BatchSendMessageModel;
import com.qmmessage.sdk.models.BatchSendMessageResult;
import com.qmmessage.sdk.models.SendMessageModel;
import com.qmmessage.sdk.models.SendMessageResult;

/**
 * sms client
 * @author qm
 */
public class SmsClient {

    private final ClientProfile profile;
    public SmsClient(ClientProfile profile) {
        this.profile = profile;
    }

    /**
     * send single message
     * @param model message obj
     * @return result
     * @throws QmMessageSdkException qm exception
     */
    public SendMessageResult sendMessage(SendMessageModel model) throws QmMessageSdkException {
        SendMessageResult result = model.internalRequest(this.profile, SendMessageResult.class);
        if (result != null) {
            result.setSuccess(result.getCode() != null && result.getCode() == 200);
        }
        return result;
    }

    /**
     * send batch message
     * @param model message obj
     * @return result
     * @throws QmMessageSdkException qm exception
     */
    public BatchSendMessageResult batchSendMessage(BatchSendMessageModel model) throws QmMessageSdkException {
        BatchSendMessageResult result = model.internalRequest(this.profile, BatchSendMessageResult.class);
        if (result != null) {
            result.setSuccess(result.getCode() != null && result.getCode() == 200);
        }
        return result;
    }
}
